package Action;



import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import Service.PlService;
import VO.AlterPlVO;
import VO.PLVO;
import VO.PlcAddVO;
import VO.PlcVO;


public class PlAction {

	private PlService pls;
	private String pname;
	private int page;
	private int pageSize;
	private List<PLVO> listPVO;
	private List<PlcVO> listPlcVO;//只需要get方法
	private int totalPage;
	public void setAlterPlVO(AlterPlVO alterPlVO) {
		this.alterPlVO = alterPlVO;
	}
	private int pid;
	private int plcPage;
	private int plcPageSize;
	private List<PlcAddVO> listPlcAddVO;//set和get方法都需要
	private AlterPlVO alterPlVO;
	
	public List<PlcAddVO> getListPlcAddVO() {
		return listPlcAddVO;
	}

	public void setListPlcAddVO(List<PlcAddVO> listPlcAddVO) {
		this.listPlcAddVO = listPlcAddVO;
	}

	public void setListPlcVO(List<PlcVO> listPlcVO) {
		this.listPlcVO = listPlcVO;
	}

	public List<PlcVO> getListPlcVO() {
		return listPlcVO;
	}
	
	public void setPlcPage(int plcPage) {
		this.plcPage = plcPage;
	}
	public void setPlcPageSize(int plcPageSize) {
		this.plcPageSize = plcPageSize;
	}
	public void setPid(int pid) {
		this.pid = pid;
	}
	//判断文本框里是否为空，不为空就将文本框的内容添加到数据库。跳到遍历品类的方法中，并传参page与pageSize。
	public String addPl(){
		if(pname.equals("")){	
			return "null";
		}
		pls.addPl(pname);
		return "addPl";
	}
	public int getPid() {
		return pid;
	}
	//根据page与pageSize得到PLVO对象集合，从数据库得到品类总数，根据pageSize计算出总页数。转到pl_list.jsp页面。
	public String showPList(){
		listPVO=pls.showPList(page,pageSize);
		int total=pls.getAll();
		if(total%pageSize==0){
			totalPage=total/pageSize;
		}else{
			totalPage=total/pageSize+1;
		}
		return "showPList";
	}
	public String deletePl(){
		pls.deletePl(pid);
		return "deletePl";
	}
	public String alterPl(){
		System.out.println(alterPlVO);
		pls.alterPl(alterPlVO);
		return "deletePl";
	}
	public AlterPlVO getAlterPlVO() {
		return alterPlVO;
	}







	public String showPlInfo(){
		
		listPlcVO=pls.showPlInfo(pid);
		System.out.println(listPlcVO);
		pname=pls.showPlName(pid);
		System.out.println(pname);
		return "showPlInfo";
		
	}
	public String  addPlc(){
		pls.addPlc(listPlcAddVO);
		System.out.println("success");
		return "addPlc";
	}

	//展示pl_info.jsp时需要用到品类名字。此时pname属性的值为showP了Info()方法中为pname赋的值。
public String getPname() {
		return pname;
	}
	//添加品类时，add_pl.jsp提交过来表单的内容。
	public void setPname(String pname) {
		this.pname = pname;
	}
public int getTotalPage() {
		return totalPage;
	}
public void setListPVO(List<PLVO> listPVO) {
		this.listPVO = listPVO;
	}
public List<PLVO> getListPVO() {
		return listPVO;
	}
	public void setPage(int page) {
		this.page = page;
	}
	public int getPage() {
		return page;
	}
	public int getPageSize() {
		return pageSize;
	}
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	//添加品类时，从form表单获取的品类名称。
//	public void setPname(String pname) {
//		this.pname = pname;
//	}
	public void setPls(PlService pls) {
		this.pls = pls;
	}

}
